# Maintainer: Sergej Pupykin <arch+pub@sergej.pp.ru>
# Maintainer: Colin Woodbury <colingw@gmail.com>

pkgname=haskell-zlib
pkgver=0.6.3.0
pkgrel=38
pkgdesc="Compression and decompression in the gzip and zlib formats"
url="https://hackage.haskell.org/package/zlib"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'zlib')
makedepends=('ghc' 'uusi' 'haskell-quickcheck' 'haskell-tasty' 'haskell-tasty-quickcheck')
source=(https://hackage.haskell.org/packages/archive/zlib/${pkgver}/zlib-${pkgver}.tar.gz)
sha512sums=('95daae13c5d5458fd7c610ce4cc686dc7af477364c4dcf3d31abede84f6e4b4e70ea255f7ded586d46d9bb6298d19c93b8856eec16c6002265ed076e52bf9a21')

prepare() {
    cd zlib-$pkgver
    gen-setup
}

build() {
    cd zlib-$pkgver
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-non-blocking-ffi -fpkg-config -f-bundled-c-zlib
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register   --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd zlib-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd zlib-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/${pkgname}/LICENSE
    rm -f "$pkgdir"/usr/share/doc/${pkgname}/LICENSE
}
